﻿using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour
{

    public float life;
    public float enemySpeed;
    public Animator anim0, anim1, anim2;
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * enemySpeed * Time.deltaTime);
        if (transform.position.y < -6.5)
        {
            Destroy(gameObject);
        }
        if (life <= 0)
        {
            if (gameObject.tag == "enemy0")
            {
                anim0.SetBool("IsEnemy0Dead", true);
                Destroy(gameObject, 1);
            }
            else if (gameObject.tag == "enemy1")
            {
                anim1.SetBool("IsEnemy1Dead", true);
                Destroy(gameObject, 1.1f);
            }
            else if (gameObject.tag == "enemy2")
            {
                anim2.SetBool("IsEnemy2Dead", true);
                Destroy(gameObject, 1.1f);
            }
        }
    }

    void OnTriggerEnter2D(Collider2D coll)
    {
        if (coll.gameObject.tag == "bullet")
        {
            life--;
        }
    }

}
